package com.yulan.bankback.mapper.bank;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yulan.bankback.entity.model.bank.UserCapitalFlow;
import com.yulan.bankback.entity.dto.bank.UserMoneyFlowGroup;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface UserCapitalFlowMapper extends BaseMapper<UserCapitalFlow> {

    @Select("select time, sum(money) from user_capital_flow where type = #{type} and " +
            "uid = #{uid} and time > NOW() - INTERVAL ${interval} group by time")
    List<UserMoneyFlowGroup> getFlowByIntervalAndType(@Param("type") String type,
                                                      @Param("uid")String uid,
                                                      @Param("interval") String interval);


    @Select("select count(*) from user_capital_flow where type = #{type} and " +
            "uid = #{uid} and time > NOW() - INTERVAL ${interval}")
    Integer getTotal(@Param("type") String type,
                     @Param("uid")String uid,
                     @Param("interval") String interval);


    @Select("select time, money_src, money, type from user_capital_flow where  " +
            "uid = #{uid} and time > NOW() - INTERVAL ${interval}")
    List<UserCapitalFlow> getFlowByInterval(@Param("uid")String uid,
                                               @Param("interval") String interval);


}
